#!/usr/bin/env python
# -*- encoding:utf-8 -*-

from flask import Flask, request
app = Flask(__name__)
import receiver

@app.route('/receive', methods=["GET", "POST"])
def msg_receive():
    if request.method = "GET":
        params = {
            'signature': request.args.get('signature'),
            'timestamp': request.args.get('timestamp'),
            'nonce': request.args.get('nonce'),
            'echostr': request.args.get('echostr')
        }
        if receiver.chk_apptoken(params['signature'], params['timestamp'], params['nonce']):
            return params['echostr']
    else:
        receiver.post_message(request.data)
    